package com.qs.eggs.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.qs.eggs.Constants;
import com.qs.eggs.R;
import com.qs.eggs.bean.OrderBean;
import com.qs.eggs.bean.SortBean;
import com.qs.eggs.refresh.adapter.BaseRecyclerAdapter;


public class OrderManagerAdapter extends BaseRecyclerAdapter<OrderBean> implements BaseRecyclerAdapter.OnLoadingHeaderCallBack {


    public OrderManagerAdapter(Context context, int mode) {
        super(context, mode);

        setOnLoadingHeaderCallBack(this);
    }

    @Override
    public RecyclerView.ViewHolder onCreateHeaderHolder(ViewGroup parent) {
        return new HeaderViewHolder(mHeaderView);
    }

    @Override
    public void onBindHeaderHolder(RecyclerView.ViewHolder holder, int position) {

    }

    @Override
    protected RecyclerView.ViewHolder onCreateDefaultViewHolder(ViewGroup parent, int type) {
        return new SortViewHolder(mInflater.inflate(R.layout.item_order, parent, false));
    }

    @Override
    protected void onBindDefaultViewHolder(RecyclerView.ViewHolder holder, OrderBean item, int position) {
        final SortViewHolder vh = (SortViewHolder) holder;

        vh.mOrderNumber.setText("订单号: "+item.getOrderno());
        vh.mContent.setText(item.getNote());
        vh.mPrice.setText("¥"+item.getTotalmoney());
        vh.mCount.setText("X "+item.getTotalcount());
        vh.mAllMoney.setText("共"+item.getTotalcount()+"件商品、合计: "+"¥"+item.getTotalmoney());
        vh.mCreateTime.setText(item.getCreatetime());
      //  vh.mAvatar.setImageURI(Constants.URL_BASE+"productimages/"+item.getAutoname());

        if(item.getOrderstatus().equals("0")){
            vh.mOrderState.setText("待发货");
            vh.mHandler.setText("去付款");
            vh.mHandler.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    handlerOrder();
                }
            });
        }else if (item.getOrderstatus().equals("1")){
            vh.mOrderState.setText("待收货");
            vh.mHandler.setText("去付款");
            vh.mHandler.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    handlerOrder();
                }
            });
        }else if (item.getOrderstatus().equals("2")){
            vh.mOrderState.setText("待收货");
            vh.mHandler.setText("去付款");
            vh.mHandler.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    handlerOrder();
                }
            });
        }else if (item.getOrderstatus().equals("3")){
            vh.mOrderState.setText("待收货");
            vh.mHandler.setText("确认收货");
            vh.mHandler.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    handlerOrder();
                }
            });
        }else if (item.getOrderstatus().equals("4")){
            vh.mOrderState.setText("待评价");
            vh.mHandler.setText("待评价");
            vh.mHandler.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    handlerOrder();
                }
            });
        }else if (item.getOrderstatus().equals("5")){
            vh.mOrderState.setText("待收货");
            vh.mHandler.setText("去付款");
            vh.mHandler.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    handlerOrder();
                }
            });
        }
    }

    /**
     * 处理订单
     */
    private void handlerOrder(){

    }
    private static class SortViewHolder extends RecyclerView.ViewHolder {
        TextView mOrderNumber,mOrderState,mContent,mPrice,mCount,mAllMoney,mCreateTime,mHandler;
        ImageView mCollect;
        SimpleDraweeView mAvatar;


        public SortViewHolder(View itemView) {
            super(itemView);

            mOrderNumber=(TextView) itemView.findViewById(R.id.tv_order_number);
            mOrderState=(TextView) itemView.findViewById(R.id.tv_order_state);
            mContent=(TextView) itemView.findViewById(R.id.tv_content);
            mPrice=(TextView) itemView.findViewById(R.id.tv_price);
            mCount=(TextView) itemView.findViewById(R.id.tv_count);
            mAllMoney=(TextView) itemView.findViewById(R.id.tv_allmoney);
            mCreateTime=(TextView) itemView.findViewById(R.id.tv_createtime);
            mHandler=(TextView) itemView.findViewById(R.id.tv_hander);
            mAvatar=(SimpleDraweeView) itemView.findViewById(R.id.propic);
        }
    }
}
